package ThreadDemo;


public class ThreadDemo20 {
    static class Singleton{
//饿汉单例模式，在类加载时就已经创建了一个实例（实例创建的比较早）
        //将构造方法设置成私有就无法在类外创建实例
        private Singleton(){}
        private static Singleton instance=new Singleton();
        public static Singleton getInstance(){
            return instance;
        }
    }
    public static void main(String[] args) {
        Singleton s1=Singleton.getInstance();
        Singleton s2=Singleton.getInstance();
        System.out.println(s1==s2);
    }
}
